//
//  LGCultureOriginViewController.m
//  ligenyun
//
//  Created by Mac on 2018/4/4.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGCultureOriginViewController.h"
#import "LGCultureNameScrolViewController.h"
#import "LGCultureTuTengViewController.h"
#import "LGCultureNameDetailViewController.h"
@interface LGCultureOriginViewController ()
@property(nonatomic, strong) UITextField                     *textFiled;
@end

@implementation LGCultureOriginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"百家姓";
    [self.tableView st_autoAdjustAllResponder];
    [self configSubView];
    [self configTableFooterView];
    // Do any additional setup after loading the view.
}
#pragma mark --subView
- (void)configSubView{
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 30)];
    header.backgroundColor = [UIColor whiteColor];
    UIImageView * bannerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 150)];
    bannerImageView.image = [UIImage imageNamed:@"百家姓banner"];
    [header addSubview:bannerImageView];
    __weak typeof(self) weakSelf =  self;
#pragma mark --头部第一部分
    UIView * header1 = [TMUtils headerViewWithTitle:@"《百家姓》姓氏起源"];
    header1.top = bannerImageView.bottom;
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSectedOriginView)];
    [header1 addGestureRecognizer:tap];
    
    [header1 st_showBottomLine];
    [header addSubview:header1];
    NSString * conten = @"赵钱孙李，周吴郑王。冯陈褚卫，蒋沈韩杨。朱秦尤许何吕施张。孔曹严华，金魏陶姜。戚谢邹喻，柏水窦章。云苏潘葛，奚范彭郎。鲁韦昌马，苗凤花方。俞任袁柳，酆鲍史唐。费廉岑薛，雷贺倪汤。滕殷罗毕，郝邬安常。乐于时傅，皮卞齐康";
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(15, header1.bottom, UIScreenWidth - 30, 30)
                                                     text:conten
                                                textColor:FirstTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    
    
    [NSString lableAutoAdjustheightWithLabel:titleLable];
    [header addSubview:titleLable];
    STLabel * indicatiorLable = [[STLabel alloc] initWithFrame:CGRectMake(15, titleLable.bottom  +20, 200, 30)
                                                          text:@"请输入姓氏:"
                                                textColor:SecendTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentCenter];
    
    [NSString lableAutoAdjustWitdhWithLabel:indicatiorLable];
    [header addSubview:indicatiorLable];
    
    self.textFiled = [[UITextField alloc] initWithFrame:CGRectMake(indicatiorLable.right, 0, 140, 30)];
    self.textFiled.placeholder = @"请输入姓氏";
    [self.textFiled st_setBorderWith:1 borderColor:TM_lineColor cornerRadius:4];
     self.textFiled.centerY = indicatiorLable.centerY;
    self.textFiled.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 30)];
    self.textFiled.leftViewMode = UITextFieldViewModeAlways;
    [header addSubview:self.textFiled];
    
    STButton * findButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 100, 30)
                                                     title:@"查询姓氏起源"
                                                titleColor:FirstTextColor
                                                 titleFont:14
                                              cornerRadius:4
                                           backgroundColor:FlatGray
                                           backgroundImage:nil
                                                     image:nil];
    findButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [findButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedFindButton];
    }];
    findButton.right = UIScreenWidth - 15;
    findButton.centerY = indicatiorLable.centerY;
    [header addSubview:findButton];
    
    UIView * grawView1 = [[UIView alloc] initWithFrame:CGRectMake(0, indicatiorLable.bottom  +20, UIScreenWidth, 10)];
    grawView1.backgroundColor = self.tableView.backgroundColor;
    [header addSubview:grawView1];
#pragma mark --header 2
    
    UIView * view2 = [TMUtils headerViewWithTitle:@"姓氏新闻"];
    view2.top = grawView1.bottom;
    [view2 st_showBottomLine];
    [header addSubview:view2];
    
    STLabel * view2titleLable = [[STLabel alloc] initWithFrame:CGRectMake(15, view2.bottom, UIScreenWidth - 30, 44)
                                                     text:@"中华家谱编纂工程"
                                                textColor:SecendTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [header addSubview:view2titleLable];
    
    
    STLabel * view2timeLable = [[STLabel alloc] initWithFrame:CGRectMake(15, view2.bottom, 200, 44)
                                                          text:@"2018年04月04日"
                                                     textColor:SecendTextColor
                                                          font:14
                                                   isSizetoFit:NO
                                                 textAlignment:NSTextAlignmentRight];
    view2timeLable.right = UIScreenWidth - 15;
    [header addSubview:view2timeLable];
    
    UIView * view2line = [[UIView alloc] initWithFrame:CGRectMake(0, view2titleLable.bottom, UIScreenWidth, 1)];
    view2line.backgroundColor = TM_lineColor;
    [header addSubview:view2line];
    
    NSString * view2content = @"光明网讯(记者周洪双) 2017年5月27日,中国文化信息协会家文化工作委员会在京成立。家文化工作委员会将重点开展中华家谱编纂工程和“家家有谱”工程。";
    STLabel * view2desLable = [[STLabel alloc] initWithFrame:CGRectMake(15, view2line.bottom + 10, UIScreenWidth - 30, 44)
                                                          text:view2content
                                                     textColor:SecendTextColor
                                                          font:14
                                                   isSizetoFit:NO
                                                 textAlignment:NSTextAlignmentLeft];
    [NSString lableAutoAdjustheightWithLabel:view2desLable];
    [header addSubview:view2desLable];
    
    UIView * grawView2 = [[UIView alloc] initWithFrame:CGRectMake(0, view2desLable.bottom  +20, UIScreenWidth, 10)];
    grawView2.backgroundColor = self.tableView.backgroundColor;
    [header1 addSubview:grawView2];
    
    



    
    
    header.height = grawView2.bottom;
    self.tableView.tableHeaderView = header;
    
}
#pragma mark --header3
- (void)configTableFooterView{
    UIView * footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 30)];
    footer.backgroundColor = self.tableView.backgroundColor;
    UIView * view3 = [TMUtils headerViewWithTitle:@"姓氏图腾"];
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSectedTuTengView)];
    [view3 addGestureRecognizer:tap];
    [footer addSubview:view3];
    
    CGFloat imageWith = (UIScreenWidth - 15 * 5)/4;
    NSArray *  imageNams = @[@"图腾01",@"图腾02",@"图腾03",@"图腾04"];
    for (NSInteger i = 0; i <imageNams.count ; i ++ ) {
        UIImageView * imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, view3.bottom + 15, imageWith, imageWith)];
        imageview.image = [UIImage imageNamed:imageNams[i]];
        [footer addSubview:imageview];
        imageview.left = 15  + 15 * i + i *imageWith;
        footer.height = imageview.bottom + 15;
        
    }
    self.tableView.tableFooterView = footer;
}
#pragma mark --Action Method
- (void)onSelctedFindButton{
    if (!self.textFiled.text.length) {
        [SVProgressHUD showErrorWithStatus:@"请输入姓氏"];
        return;
    }
    LGCultureNameScrolViewController * vc =  [LGCultureNameScrolViewController new];
    vc.firstName = self.textFiled.text;
    [self.navigationController pushViewController:[LGCultureNameScrolViewController new] animated:YES];
}
- (void)onSectedOriginView{
      [self.navigationController pushViewController:[LGCultureNameDetailViewController new] animated:YES];
    
}
- (void)onSectedTuTengView{
    [self.navigationController pushViewController:[LGCultureTuTengViewController new] animated:YES];
}
@end
